<template>
	<view class="container">
		<!-- 搜索框 -->
		<uv-search placeholder="请输入搜索内容" v-model="keyword" @change="loadData" @search="loadData"
			@custom="loadData"></uv-search>

		<!-- 列表 -->
		<view class="list">
			<view v-for="(item, index) in list" :key="index" class="list-item" @click="selectExpress(item)">
				{{ item.name }}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword: '',
				list: [],
				index: -1,
			}
		},
		onLoad(options) {
			this.index = options.index
			this.loadData()
		},
		methods: {
			async loadData() {
				uni.showLoading({
					title: '加载中',
					mask: false
				});
				uni.request({
					url: '/wanlshop.common/getExpressList',
					method: 'GET',
					data: {
						search: this.keyword
					},
					success: res => {
						this.list = res.data || []
					},
					fail: err => {
						console.error(err)
					},
					complete() {
						uni.hideLoading();
					}
				})
			},
			selectExpress(item) {
				item.index = this.index;
				uni.$emit('selectExpressItem', {
					data: item,
				})
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 22rpx;
	}

	.list {
		margin-top: 20rpx;
	}

	.list-item {
		padding: 20rpx;
		border-bottom: 1px solid #eee;
		font-size: 28rpx;
		color: #333;
	}

	.list-item:active {
		background-color: #f5f5f5;
	}
</style>